package com.jz.netthings.application.utils;

import com.alibaba.fastjson.JSONObject;
import com.jz.netthings.appengine.baseData.ProviderData;
import com.jz.netthings.appengine.support.BeanSupport;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.netty.protocol.bean.ZxdcMsgPacket;
import com.jz.netthings.utils.HttpRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * 营运管理的工具类
 */
public class AppUtils {

    static Logger logger = LoggerFactory.getLogger(AppUtils.class);
    /**
     * 发送修改分配机浆员状态的消息，给engine模块
     * @param providerData
     * @param urlPrefix url前缀，IP + 端口 ：http://127.0.0.1:8888
     * @throws AdscmSystemException
     */
    public static void sendMsgToAllotCtxs(ProviderData providerData,String urlPrefix){
        try {
            logger.info("发送修改分配机浆员状态的消息，给engine模块");
            String url = urlPrefix + "/netthings/engine/base/applicationMsgToAllot";

            ZxdcMsgPacket zxdcMsgPacket = BeanSupport.loadToAllotMsg(providerData, null);
            String json = JSONObject.toJSONString(zxdcMsgPacket);
            String result = HttpRequest.sendPost(url,json);
            logger.info(result);
        }catch (Exception e){
            logger.error("发送修改分配机浆员状态的消息，给engine模块 失败",e);
        }
    }


    public static void main(String[] args) throws AdscmSystemException {
        sendMsgToAllotCtxs(null,"http://localhost:8888");
    }

}
